package services;

import models.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import persistence.ProductMapper;

import java.util.List;

/**
 * Created by Fpt-Shop on 12/26/13.
 */
@Transactional
@Service
public class ProductService {
    @Autowired
    private ProductMapper productMapper;

    // insert new product
    public void insertProduct(Product pro) {
        try {
            productMapper.insertProduct(pro);
        } catch (Exception e) {
            e.getMessage();
        }
    }


    //get Product by id product
    public Product getProductById(Integer cusId) {
        try {
            return productMapper.getProductById(cusId);
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }

    //get product by name
    public List<Product> getProductsLikeName(String name) {
        try {
            return productMapper.getProductsLikeName(name);
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }

    //get All product
    public List<Product> getAllProducts() {
        try {
            List<Product> cus= productMapper.getAllProducts();
            return cus;
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }


    //update product
    public void updateProduct(Product pro) {
        try {
            productMapper.updateProduct(pro);
        } catch (Exception e) {
            e.getMessage();
        }
    }


    //delete product by id product
    public void deleteProduct(Integer cusId) {
        try {
            productMapper.deleteProduct(cusId);
        } catch (Exception e) {
            e.getMessage();
        }
    }
}
